package com.ruoyi.system.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.ComplainSuggest;
import com.ruoyi.system.service.IComplainSuggestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 投诉建议Controller
 *
 * @author ...
 * @date 2022-03-18
 */
@RestController
@RequestMapping("/system/suggest")
public class ComplainSuggestController extends BaseController {
    @Autowired
    private IComplainSuggestService complainSuggestService;

    /**
     * 查询投诉建议列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ComplainSuggest complainSuggest) {
        startPage();
        List<ComplainSuggest> list = complainSuggestService.selectComplainSuggestList(complainSuggest);
        return getDataTable(list);
    }

    /**
     * 获取投诉建议详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return AjaxResult.success(complainSuggestService.selectComplainSuggestById(id));
    }

    /**
     * 查询我的
     * @return
     */
    @GetMapping("/my")
    public AjaxResult getMy(){
        List<ComplainSuggest> my = complainSuggestService.getMy();
        return AjaxResult.success(my);
    }

    /**
     * 新增投诉建议
     */
    @PostMapping
    public AjaxResult add(@RequestBody ComplainSuggest complainSuggest) {
        complainSuggest.setCreateUser(SecurityUtils.getUserId().intValue());
        complainSuggest.setCreateTime(DateUtils.getNowDate());
        return toAjax(complainSuggestService.insertComplainSuggest(complainSuggest));
    }

    /**
     * 修改投诉建议
     */
    @PutMapping
    public AjaxResult edit(@RequestBody ComplainSuggest complainSuggest) {
        complainSuggest.setReplyUser(SecurityUtils.getUserId().intValue());
        complainSuggest.setReplyTime(DateUtils.getNowDate());
        complainSuggest.setUpdateUser(SecurityUtils.getUserId().intValue());
        complainSuggest.setUpdateTime(DateUtils.getNowDate());
        return toAjax(complainSuggestService.updateComplainSuggest(complainSuggest));
    }

    /**
     * 删除投诉建议
     */
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(complainSuggestService.deleteComplainSuggestByIds(ids));
    }
}
